package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Nurse;
import com.ruoyi.system.service.INurseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医护信息Controller
 * 
 * @author 王帅
 * @date 2024-08-24
 */
@Controller
@RequestMapping("/system/nurse")
public class NurseController extends BaseController
{
    private String prefix = "system/nurse";

    @Autowired
    private INurseService nurseService;


    @GetMapping()
    public String nurse()
    {
        return prefix + "/nurse";
    }

    /**
     * 查询医护信息列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Nurse nurse)
    {
        startPage();
        List<Nurse> list = nurseService.selectNurseList(nurse);
        return getDataTable(list);
    }

    /**
     * 导出医护信息列表
     */

    @Log(title = "医护信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Nurse nurse)
    {
        List<Nurse> list = nurseService.selectNurseList(nurse);
        ExcelUtil<Nurse> util = new ExcelUtil<Nurse>(Nurse.class);
        return util.exportExcel(list, "医护信息数据");
    }

    /**
     * 新增医护信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医护信息
     */

    @Log(title = "医护信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Nurse nurse)
    {
        return toAjax(nurseService.insertNurse(nurse));
    }

    /**
     * 修改医护信息
     */

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Nurse nurse = nurseService.selectNurseById(id);
        mmap.put("nurse", nurse);
        return prefix + "/edit";
    }

    /**
     * 修改保存医护信息
     */

    @Log(title = "医护信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Nurse nurse)
    {
        return toAjax(nurseService.updateNurse(nurse));
    }

    /**
     * 删除医护信息
     */

    @Log(title = "医护信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(nurseService.deleteNurseByIds(ids));
    }
}
